# 0.导包
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
# 1.获取数据
data = pd.read_csv('breast-cancer-wisconsin.csv')
# print(data.info())
# 2.数据预处理
# 2.1 缺失值
data = data.replace(to_replace='?', value=np.NAN)
data = data.dropna()
# 2.2 获取特征和目标
x = data.iloc[:, 1:-1]
y = data.iloc[:, -1]
# 2.3 划分数据集
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=22)

# 3.特征工程
transfer = StandardScaler()
x_train = transfer.fit_transform(x_train)
x_test = transfer.transform(x_test)
# 4.模型训练
LR =LogisticRegression()
LR.fit(x_train,y_train)
# 5.模型评估
print(LR.score(x_test, y_test))
print(LR.predict(x_test))
